import uuid

from flask import jsonify, render_template, Blueprint, redirect

from util.FileUtil import list_files
from util.OsUtil import execute_cmd

index_view = Blueprint('index', __name__)
index_view.url_prefix = ""


@index_view.route('/')
def index():
    return redirect('/view/articles/1')


@index_view.route('/list')
def file_list():
    files = list_files("C:/")
    return jsonify(files)


@index_view.route('/cmd')
def cmd():
    cmd = '''E: &\
    cd E:\Iris4_copy\iris4_dpmc &\
    git checkout IRIS4_R2.27.4 &\
    '''
    execute_cmd(cmd)
    return 'ok'


@index_view.route('/hello/<name>')
def hello(name=None):
    return render_template('index.html', name=name)


@index_view.route('/uuid')
def get_uuid():
    return str(uuid.uuid4())
